#include <stdio.h>
#include<stdio.h>
#include <sys/types.h>          /* See NOTES */
#include <sys/socket.h>
#include <linux/in.h>  //sockaddr_in
#include <stdlib.h>
#include <string.h>
int main(int argc, const char *argv[])
{
	int sockfd;
	sockfd=socket(AF_INET,SOCK_STREAM,0);
	if(sockfd<0)
	{
		perror("socket err");
		exit(-1);
	}
	struct sockaddr_in serveraddr;
	serveraddr.sin_family=AF_INET;
	serveraddr.sin_port=htons(atoi(argv[2]));
	serveraddr.sin_addr.s_addr=inet_addr(argv[1]);
	socklen_t serverlen=sizeof(serveraddr);

	if(connect(sockfd,(struct sockaddr *)&serveraddr,serverlen)<0)
	{
		perror("connect errr");
		exit(-1);
	}
	printf("connect ok\n");
	char buf[128]={0};
	while(1)
	{
		fgets(buf,sizeof(buf),stdin);
		buf[strlen(buf)-1]=0;
		send(sockfd,buf,sizeof(buf),0);
	}
	close(sockfd);
	return 0;
}
